package com.lanzchina.lanclass.handle;

import com.lanzchina.lanclass.domain.Result;
import com.lanzchina.lanclass.utils.ResultUtil;
import feign.Feign;
import feign.RetryableException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by qiangjindong
 * 2018-2018-10 20:15
 */
@ControllerAdvice
@ResponseBody
public class ExceptionHandle extends RuntimeException {

    private static final Logger logger = LoggerFactory.getLogger(ExceptionHandle.class);

    @ExceptionHandler(value = Exception.class)
    public Result handle(Exception e) {
        if (e instanceof RetryableException) {
            logger.info("【外部请求】: ", e);
            return ResultUtil.error(0, "获取openId失败");
        }
        logger.info("【系统异常】: ", e);
        return ResultUtil.error(0, e.getLocalizedMessage());
    }

}
